package com.jumi.microservice.service.logistics.express;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jumi.microservice.dto.logistics.Logistics;
import com.jumi.microservice.dto.logistics.LogisticsSearchRequest;
import com.jumi.microservice.dto.logistics.LogisticsSearchResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author by mazhao
 * @Classname DefaultExpress
 * @Description TODO
 * @Date 2020/8/22 10:29
 */
@Component
public class DefaultExpress extends ResponseController{

    private static final Logger log = LoggerFactory.getLogger(DefaultExpress.class);

    public LogisticsSearchResponse logisticsSearch(LogisticsSearchRequest request){
        log.info("快递鸟查询参数[{}]", JSON.toJSONString(request));
        JSONArray jsonArray = null;
        try {
            //其他快递业务逻辑实现
            KdniaoTrackQueryAPI api = new KdniaoTrackQueryAPI();
            String result = api.getOrderTracesByJson(request.getExpressCode(), request.getLogisticsNo());
            log.info("请求返回结果[{}]",result);
            JSONObject json = JSONObject.parseObject(result);
            jsonArray = json.getJSONArray("Traces");
        } catch (Exception e) {
            log.error("快递鸟查询出错[{}]",e.getMessage());
        }
        LogisticsSearchResponse logisticsSearchResponse = checkResult(jsonArray,request);
        return controller(logisticsSearchResponse,jsonArray,"AcceptStation","AcceptTime");
    }

}
